package com.qlylkj.lbk.model.repository

import com.qlylkj.lbk.model.api.BaseRepository
import com.qlylkj.lbk.model.api.CommonApi
import com.qlylkj.lbk.model.api.ResultResponse
import com.qlylkj.lbk.model.api.RetrofitHelper
import com.qlylkj.lbk.model.bean.BannerList
import com.qlylkj.lbk.model.bean.Upload
import okhttp3.MultipartBody
import java.io.File

class CommonRepository : BaseRepository() {

    private val commonApi by lazy { RetrofitHelper.getService(CommonApi::class.java) }

    private fun requestBodyUploadFile(uploadFile: File): MultipartBody.Part {
        return requestMultipartBody(uploadFile)
    }

    suspend fun uploadFile(uploadFile: File): ResultResponse<String> {
        return safeApiCallEntity(
            call = { requestUploadFile(uploadFile) },
            errorMessage = "上传图片失败"
        )
    }

    private suspend fun requestUploadFile(uploadFile: File): ResultResponse<String> {
        val response = commonApi.uploadFile(requestBodyUploadFile(uploadFile))
        return executeEntityResponse(response, {

        })
    }

    suspend fun getBannerList(): ResultResponse<BannerList> {
        return safeApiCallEntity(
            call = { requestGetBannerList() },
            errorMessage = "获取banner数据错误"
        )
    }

    private suspend fun requestGetBannerList(): ResultResponse<BannerList> {
        val response = commonApi.getBannerList()
        return executeEntityResponse(response, {

        })
    }

}